package com.ld.collegetask.utils;


import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.CardView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.ld.collegetask.R;


/**
 * @Date 2017/7/4.
 * @Description 提示弹出框.
 */
public class CameraPopup extends PopupWindow {
    private OnCallClickEvent mClickEvent;

    public interface OnCallClickEvent {
        void onCallClick(int position);
    }

    public CameraPopup(Context context, View parent, OnCallClickEvent clickEvent) {
        this.mClickEvent = clickEvent;
        View view = View.inflate(context, R.layout.popup_camera_album, null);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //PopupWindow响应返回键，那么必须给PopupWindow设置一个背景才行
        setBackgroundDrawable(new ColorDrawable(0x00000000));
        setFocusable(true);
        //点击区域外不关闭弹框
        setOutsideTouchable(true);
        setContentView(view);
        showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        update();
        ((TextView) view.findViewById(R.id.tv_album)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                mClickEvent.onCallClick(0);
            }
        });

        ((TextView) view.findViewById(R.id.tv_camera)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                mClickEvent.onCallClick(1);
            }
        });
        ((CardView) view.findViewById(R.id.cv_cancel)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }


}